package com.hdu;


public class Main {
    public static void main(String[] args) {
        StudentService studentService = new StudentService();
        IStudentService enhancedStudentService = Proxy.newProxyInstance(
                studentService.getClass().getClassLoader(),
                IStudentService.class,
                (proxy, method, args1) -> {
                    if (method.getName().equals("hello")) {
                        System.out.println("前置增强");
                        Object res = method.invoke(studentService, args1);
                        System.out.println("后置增强");
                        return res;
                    }
                    else {
                        return method.invoke(studentService, args1);
                    }
                }
        );
        enhancedStudentService.hello();
    }
}